<!DOCTYPE html>
<html>
<head>
    <title>首页</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link type="text/css" rel="stylesheet" href="../css/bootstrap.css">
    <link type="text/css" rel="stylesheet" href="../css/style.css">
    <script type="text/javascript" src="../../js/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="../js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../layer/layer.js"></script>
    <script type="text/javascript" src="../js/cart.js"></script>
    <script type="text/javascript" src="../js/auth.js"></script>
    <script type="text/javascript" src="../js/CookieShop.js"></script>
</head>
<body>
<!--header-->
<div class="header">
    <div class="container">
        <nav class="navbar navbar-default" role="navigation">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <h1 class="navbar-brand"><a href="./index"></a></h1>
            </div>
            <!--navbar-header-->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li><a href="./index.html">首页</a></li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle active" data-toggle="dropdown">商品分类<b class="caret"></b></a>
                        <ul class="dropdown-menu multi-column columns-2">
                            <li>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <h4>商品分类</h4>
                                        <ul class="multi-column-dropdown" id="goodsTypeMenu">
                                            <li><a class="list" href="./goods_list.html">全部系列</a></li>
                                        </ul>
                                    </div>
                                </div>
                            </li>
                        </ul>
                    </li>
                    <li><a href="./goodsrecommend_list.html?recommendTypeId=2">热销</a></li>
                    <li><a href="./goodsrecommend_list.html?recommendTypeId=3">新品</a></li>


                </ul>
                <!--/.navbar-collapse-->
            </div>
            <!--//navbar-header-->
        </nav>
        <div class="header-info">
            <div class="header-right search-box">
                <a href="javascript:;"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></a>
                <div class="search">
                    <form class="navbar-form" action="./goods_search.html">
                        <input type="text" class="form-control" name="keyword">
                        <button type="submit" class="btn btn-default" aria-label="Left Align">搜索</button>
                    </form>
                </div>
            </div>

            <div class="header-right cart">
                <a href="./goods_cart.html">
                    <span class="glyphicon glyphicon-shopping-cart" aria-hidden="true"><span class="card_num"></span></span>
                </a>
            </div>
            <div class="clearfix"> </div>
        </div>
        <div class="clearfix"> </div>
    </div>
</div>
<!--//header-->
<!--products-->
<div class="products">
    <div class="container">
        <h2>全部系列</h2>

        <div class="col-md-12 product-model-sec" id="dgcontent">
        </div>
        <div style='text-align:center;'>
            <a class='btn btn-info' id="first" href="javascript:first()">首页</a>
            <a class='btn btn-info' id="prev" href="javascript:prev()">上一页</a>
            <h3 style='display:inline;'>[<span id="currentPage"></span>/<span id="totalPage"></span>]</h3>
            <h3 style='display:inline;'>[<span id="recordsCount"></span>]</h3>
            <a class='btn btn-info' id="next" href="javascript:next()">下一页</a>
            <a class='btn btn-info' id="last" href="javascript:last()">尾页</a>
            <input type='text' class='form-control' id="current" style='display:inline;width:60px;'/><a class='btn btn-info' href='javascript:void(0);' onclick='jump()'>GO</a>
        </div>
    </div>
</div>
<!--//products-->
<!--footer-->
<div class="footer">
    <div class="container">
        <div class="text-center">

        </div>
    </div>
</div>
<!--//footer-->
</body>
<script type="text/javascript">
var goodsTypeId = 0;
var mypage = 1;
var myrows = 8;
var currentPage = 1;
var pageCount = 1;
$(document).ready(function(){
countMyCart();
genGoodsTypesMenu();
decorateMainMenu();
var params = new URLSearchParams(window.location.search);
var goodsType = params.get("goodsTypeId");
if (isBlank(goodsType)) goodsTypeId = 0;
else goodsTypeId = parseInt(goodsType);
loadDataGrid(mypage,myrows);
});

function loadDataGrid(page,rows){
	$.ajax({
		type:"post",
		url: "../../custcontroller/goodsCustController/goods_list",
		data: {
			goodsTypeId:goodsTypeId,
			page:page,
		},
		dataType: 'json',
		success: function(data, textStatus) {
			debugger;
			if ( data.rows !=null ){
		        $("#dgcontent").html("");
                configPageControls(data.totalPage,data.pageNumber,data.totalCount);
                for (let i=0;i<data.rows.length;i++){
				  appendGridRow(data.rows[i]);
				}
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function appendGridRow(row){
  var rowStr = "<div class=\"product-grid\">\n"+
                "<a href=\"./goods_detail.html?id="+row.id+"\">\n"+
                "<div class=\"more-product\"><span> </span></div>\n"+
                "<div class=\"product-img b-link-stripe b-animate-go  thickbox\">\n"+
                "<img src=\"data:image/png;base64,"+row.cover+"\" class=\"img-responsive\" alt=\""+row.name+"\" width=\"240\" height=\"240\">\n"+
                "<div class=\"b-wrapper\">\n"+
                "<h4 class=\"b-animate b-from-left  b-delay03\">\n"+
                "<button href=\"./goods_detail.html?id="+row.id+"\">查看详情</button>\n"+
                "</h4>\n"+
                "</div>\n"+
                "</div>\n"+
                "</a>\n"+
                "<div class=\"product-info simpleCart_shelfItem\">\n"+
                "<div class=\"product-info-cust prt_name\">\n"+
                "<h4>"+row.name+"</h4>\n"+
                "<span class=\"item_price\">¥ "+row.price+"</span>\n"+
                "<input type=\"button\" class=\"item_add items\" value=\"加入购物车\" onclick=\"buy("+row.id+",1)\">\n"+
                "<div class=\"clearfix\"> </div>\n"+
                "</div>\n"+
                "</div>\n"+
                "</div>\n";
  $("#dgcontent").append(rowStr);
}

function showCoverImage(row){
	if(row.cover){
		return "<img style='height:100px;' border='1' src='data:image/png;base64,"+row.cover+"'/>";
	} else {
		return "<img style='height:100px;' border='1' src='../../images/blank.jpg'/>";
	}
}

function genOperationTd(row){
	var tdStr =	"<td>\n"+
				"<p>\n";
	if (row.isScroll) {
	 tdStr += "<a class=\"btn btn-info\" href=\"/admin/goods_recommend?id="+row.id+"&method=remove&typeTarget=1&pageNumber="+row.pageNumber+"&goodsTypeId="+row.goodsTypeId+"\">移出条幅</a>";
	} else {
	 tdStr += "<a class=\"btn btn-info\" href=\"/admin/goods_recommend?id="+row.id+"&method=add&typeTarget=1&pageNumber="+row.pageNumber+"&goodsTypeId="+row.goodsTypeId+"\">加入条幅</a>";
	}
	if (row.isHot) {
	 tdStr += "<a class=\"btn btn-info\" href=\"/admin/goods_recommend?id="+row.id+"&method=remove&typeTarget=2&pageNumber="+row.pageNumber+"&goodsTypeId="+row.goodsTypeId+"\">移出热销</a>";
	} else {
	 tdStr += "<a class=\"btn btn-info\" href=\"/admin/goods_recommend?id="+row.id+"&method=add&typeTarget=2&pageNumber="+row.pageNumber+"&goodsTypeId="+row.goodsTypeId+"\">加入热销</a>";
	}
	if (row.isNew) {
	 tdStr += "<a class=\"btn btn-info\" href=\"/admin/goods_recommend?id="+row.id+"&method=remove&typeTarget=3&pageNumber="+row.pageNumber+"&goodsTypeId="+row.goodsTypeId+"\">移出新品</a>";
	} else {
	 tdStr += "<a class=\"btn btn-info\" href=\"/admin/goods_recommend?id="+row.id+"&method=add&typeTarget=3&pageNumber="+row.pageNumber+"&goodsTypeId="+row.goodsTypeId+"\">加入新品</a>";
	}
	tdStr += "</p>\n"+
				"<a class=\"btn btn-success\" href=\"/admin/goods_editshow?id="+row.id+"&pageNumber="+row.pageNumber+"&goodsTypeId="+row.goodsTypeId+"\">修改</a>\n"+
				"<a class=\"btn btn-danger\" href=\"/admin/goods_delete?id="+row.id+"&pageNumber="+row.pageNumber+"&goodsTypeId="+row.goodsTypeId+"\">删除</a>\n"+
				"</td>\n";
	return tdStr;
}
</script>
</html>
